/*
 * Toedo
 * Copyright (C) 2009-2010 J. Devauchelle and contributors.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * version 3 as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 */

package org.toedo.gui.actions;

import org.eclipse.jface.action.Action;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.MessageBox;
import org.eclipse.swt.widgets.Shell;
import org.toedo.controllers.DataController;
import org.toedo.gui.translations.Messages;

public class UnsavedModifiedCheckerAction extends Action {
	
	private Shell mShell;
	
	public UnsavedModifiedCheckerAction(Shell shell) {
		mShell = shell;
	}
	
	public void run() {
		if (DataController.getInstance().getProject().isModified()) {
			MessageBox messageBox = new MessageBox(mShell,
					SWT.ICON_QUESTION | SWT.YES | SWT.NO);
			messageBox.setMessage(Messages.UnsavedModifiedCheckerAction_Message);
	        messageBox.setText(Messages.UnsavedModifiedCheckerAction_Title);
	        
	        int response = messageBox.open();
	        
	        if (response == SWT.YES) {
	        	new SaveProjectAction(false).run();
	        }
		}
	}

}
